package ${packageName}.${className_x}.service.impl;

import com.adolphor.base.entity.BaseEntity;
import com.adolphor.base.utils.PageUtil;
import com.adolphor.base.utils.UuidUtil;
import ${packageName}.${className_x}.entity.${className_d};
import ${packageName}.${className_x}.entity.${className_d}Param;
import ${packageName}.${className_x}.entity.${className_d}Vo;
import ${packageName}.${className_x}.mapper.${className_d}Mapper;
import ${packageName}.${className_x}.service.${className_d}Service;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service("${className_x}Service")
public class ${className_d}ServiceImpl implements ${className_d}Service {

    @Autowired
    private ${className_d}Mapper ${className_x}Mapper;

    @Override
    public ${className_d}Vo query(${className_d}Param param){
        return ${className_x}Mapper.query(param);
    }

    @Override
    public ${className_d}Vo queryById(String id) {
        ${className_d}Param param = new ${className_d}Param();
        param.setId(id);
        return this.query(param);
    }

    @Override
    public List<${className_d}Vo> queryByIds(List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return ${className_x}Mapper.queryByIds(ids);
    }

    @Override
    public Long count(${className_d}Param param)
        return ${className_x}Mapper.count(param);
    }

    @Override
    public List<${className_d}Vo> queryList(${className_d}Param param){
        return ${className_x}Mapper.queryList(param);
    }

    @Override
    public PageInfo<${className_d}Vo> queryPage(${className_d}Param param){
        PageUtil.beforeQueryPage(param);
        List<${className_d}Vo> list = this.queryList(param);
        return new PageInfo<>(list);
    }

    @Override
    public String insert(${className_d} entity){
        entity.setId(UuidUtil.getUuid());
        ${className_x}Mapper.insert(entity);
        return entity.getId();
    }

    @Override
    public List<String> batchInsert(List<${className_d}> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.EMPTY_LIST;
        }
        list.forEach(e -> e.setId(UuidUtil.getUuid()));
        ${className_x}Mapper.batchInsert(list);
        return list.stream().map(BaseEntity::getId).collect(Collectors.toList());
    }

    @Override
    public Integer updateById(${className_d} entity){
        return ${className_x}Mapper.updateById(entity);
    }

    @Override
    public String save(${className_d} entity){
        if (StringUtils.isEmpty(entity.getId())) {
            return this.insert(entity);
        } else {
            this.updateById(entity);
            return entity.getId();
        }
    }

    @Override
    public Integer deleteById(String id){
        ${className_d} entity = new ${className_d}();
        entity.setId(id);
        return ${className_x}Mapper.delete(entity);
    }

    @Override
    public Integer delete(${className_d} entity){
        return ${className_x}Mapper.delete(entity);
    }

    @Override
    public Integer deleteRecordById(String id){
        ${className_d} entity = new ${className_d}();
        entity.setId(id);
        return ${className_x}Mapper.deleteRecord(entity);
    }

    @Override
    public Integer deleteRecord(${className_d} entity){
        return ${className_x}Mapper.deleteRecord(entity);
    }

}